﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DCTAccess.Business
{
    public enum DateCompareTypes
    {
        Before,
        BeforeOrEqual,
        After,
        AfterOrEqual,
        Equal,
        NotEqual
    }

    public class DateCompareSQLBuilder
    {
        public static string GetSQL(string fieldName, DateCompareTypes compareType, string value, int sqlConvertType)
        {
            string sqlOperator = string.Empty;
            switch (compareType)
            {
                case DateCompareTypes.After:
                    sqlOperator = ">";
                    break;
                case DateCompareTypes.AfterOrEqual:
                    sqlOperator = ">=";
                    break;
                case DateCompareTypes.Before:
                    sqlOperator = "<";
                    break;
                case DateCompareTypes.BeforeOrEqual:
                    sqlOperator = "<=";
                    break;
                case DateCompareTypes.Equal:
                    sqlOperator = "=";
                    break;
                case DateCompareTypes.NotEqual:
                    sqlOperator = "<>";
                    break;
            }

            return string.Format(" ({0} {1} CONVERT(datetime, {2}, {3})) ", fieldName, sqlOperator, value, sqlConvertType);
        }

        public static string GetSQL(string fieldName, DateCompareTypes compareType, string value)
        {
            return GetSQL(fieldName, compareType, value, 103);
        }
    }
}
